/*
 * Copyright (C) 2013 Daniel Treffenstädt <daniel@treffenstaedt.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "OVector2D.h"

#include "OMethods.h"

O_START_NAMESPACE

Vector2D::Vector2D()
{
	m_x	= 0;
	m_y	= 0;
	m_valid	= false;
}

Vector2D::Vector2D(double x, double y)
{
	m_x	= x;
	m_y	= y;
	m_valid	= true;
}

bool Vector2D::valid()
{
	return m_valid;
}

double Vector2D::x()
{
	return m_x;
}

double Vector2D::y()
{
	return m_y;
}

double Vector2D::magnitude()
{
	double x	= Methods::pow(this->x(), 2);
	double y	= Methods::pow(this->y(), 2);

	return Methods::root(x + y);
}

void Vector2D::operator +=(Vector2D v)
{
	m_x	+= v.x();
	m_y	+= v.y();
}

Vector2D Vector2D::operator +(Vector2D v)
{
	return Vector2D(x() + v.x(), y() + v.y());
}

void Vector2D::operator -=(Vector2D v)
{
	m_x	-= v.x();
	m_y	-= v.y();
}

Vector2D Vector2D::operator -(Vector2D v)
{
	return Vector2D(x() - v.x(), y() - v.y());
}
bool Vector2D::operator <(Vector2D v)
{
	return magnitude() < v.magnitude();
}

bool Vector2D::operator <=(Vector2D v)
{
	return magnitude() <= v.magnitude();
}

bool Vector2D::operator >(Vector2D v)
{
	return magnitude() > v.magnitude();
}

bool Vector2D::operator >=(Vector2D v)
{
	return magnitude() >= v.magnitude();
}

bool Vector2D::operator ==(Vector2D v)
{
	return (x() == v.x() && y() == v.y());
}

bool Vector2D::operator !=(Vector2D v)
{
	return !((*this) == v);
}

void Vector2D::operator *=(double a)
{
	m_x	*= a;
	m_y	*= a;
}

Vector2D Vector2D::operator *(double a)
{
	return Vector2D(x() * a, y() * a);
}

void Vector2D::operator /=(double a)
{
	if (a != 0)
	{
		m_x	/= a;
		m_y	/= a;
	}
}

Vector2D Vector2D::operator /(double a)
{
	if (a != 0)
	{
		return Vector2D(x() / a, y() / a);
	}
	return Vector2D(x(), y());
}

O_END_NAMESPACE
